<template>
  <view class="container">
    <view class="head">
      <u-icon @click="returnButton()" name="arrow-left" color="#fff" size="30"></u-icon>
      <u-text text="输入核销码" color="#fff" size="22" align="center" margin="4vh 0px 0px 0px"></u-text>
    </view>
    <view class="search">
      <view class="search-box">
        <text>输入核销码</text>
        <view class="info">
          <input/>
          <view class="sub">
            <u-text text="识别" align="center" lineHeight="5vh" color="#fff" size="14"></u-text>
          </view>
        </view>
      </view>
    </view>
    <view class="content">
      <view style="font-size:18px;height: 50rpx;line-height:50rpx;width: 100%;text-align: center">
        <text>核销码 {{ CheStatement.verificationCode }}</text>
      </view>
      <view class="hr"></view>
      <u-text text="服务内容" size="18" line-height="50rpx"></u-text>
      <u-text :text="this.CheStatement.cheService.name" size="16" lineHeight="50rpx"></u-text>
      <u-text :text="this.CheStatement.cheService.intro" size="16" lineHeight="50rpx"></u-text>
      <view class="hr"></view>
      <u-text text="订单信息" size="18" line-height="50rpx"></u-text>
      <view style="font-size:16px;height: 50rpx;line-height:50rpx">预计金额:￥
        <text>{{ this.CheStatement.totalPrice }}</text>
      </view>
      <view style="font-size:16px;height: 50rpx;line-height:50rpx">实付金额:￥
        <text>{{ this.CheStatement.realPrice }}</text>
      </view>
      <view style="font-size:16px;height: 50rpx;line-height:50rpx">优惠金额:￥
        <text>{{ this.CheStatement.totalPrice - this.CheStatement.realPrice }}</text>
      </view>

      <view style="font-size:16px;height: 50rpx;line-height:50rpx">订单号:
        <text>{{ this.CheStatement.number }}</text>
      </view>
      <view style="font-size:16px;height: 50rpx;line-height:50rpx">支付时间:
        <text>{{ this.CheStatement.subscribeTime }}</text>
      </view>
    </view>
    <view class="bottom" :style="{backgroundColor: bgColor}">
      <u-text @click="show=true" :text="btnText" color="#fff" size="18" align="center" line-height="6vh"></u-text>
    </view>
    <!-- 确认核销弹窗 -->
    <u-modal :show="show" title="核销此订单" showCancelButton @cancel="show=false" @confirm="OKConfirm()">
      <view class="slot-content">
        <rich-text :nodes="content"></rich-text>
      </view>
    </u-modal>
  </view>
</template>

<script>
export default {
  data() {
    return {
      show: false,
      content: `请您仔细核对订单,此操作不可撤销<br> 请谨慎操作`,
      btnText: '确认核销',
      'bgColor': '#0662E6',
      CheStatement: {
        carId: '',
        cheCar: '',
        cheService: '',
        cheShop: '',
        cheUser: '',
        couponId: '',
        createBy: '',
        createTime: '',
        id: '',
        number: '',
        realPrice: '',
        remark: '',
        serviceId: '',
        shopId: '',
        state: '',
        subscribeTime: '',
        totalPrice: '',
        updateBy: '',
        updateTime: '',
        userId: '',
        verificationCode: '',
        verificationTime: '',
      }
    }
  },
  onLoad(option) {
    this.CheStatement = JSON.parse(option.CheStatement)
    // console.log(this.CheStatement)
  },
  methods: {
    OKConfirm() {
      const that = this;
      this.$http({
        url: `/api/management/management`,
        method: 'PUT',
        data: {
          id: this.CheStatement.id,
          state: 4,
        },
        success(res) {
          // console.log(res)
          if (res.data.code === 200) {
            uni.showToast({
              title: '核销成功',
              icon: 'none',
              duration: 2000,
            })
            that.confirm();
          } else {
            uni.showToast({
              title: '核销失败',
              icon: 'none',
              duration: 2000
            })
          }
        }
      })
    },
    confirm() {
      this.bgColor = '#808080';
      this.btnText = '已核销';
      this.show = false;
    },
    returnButton() {
      uni.$u.route('/pages/ls/enterVerificationCode/enterVerificationCode');
    },
  }
}
</script>

<style lang="scss">
page {
  soverflow: hidden;
}

.container {
  height: 100vh;
}

.head {
  background-color: #3183FB;
  width: 100%;
  height: 250px;
  overflow: auto;

  .u-icon {
    position: fixed;
    top: 4vh;
  }
}

.search {
  box-sizing: border-box;
  padding: 0vh 25rpx;
  background-color: white;
  width: 90vw;
  height: 10vh;
  margin: 0 auto;
  transform: translateY(-25vh);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1), 0 6px 20px rgba(0, 0, 0, 0.1);
  border-radius: 20rpx;

  .search-box {
    display: flex;
    align-items: center;
    height: 10vh;

    text {
      font-size: 32rpx;
      color: #3183FB;
      line-height: 6vh;
    }

    .info {
      border: 1px solid #c8c8c8;
      border-radius: 40rpx;
      width: 58vw;
      height: 6vh;
      margin-left: 2vw;
      display: flex;
      justify-content: space-between;
      align-items: center;
      box-sizing: border-box;
      padding: 0 5rpx;

      input {
        width: 35vw;
        height: 6vh;
        text-indent: 1em;
      }

      .sub {
        background-color: #3183FB;
        width: 20vw;
        height: 5vh;
        border-radius: 40rpx;
      }
    }
  }
}

.content {
  box-sizing: border-box;
  padding: 30rpx 25rpx;
  background-color: white;
  width: 90vw;
  height: 46vh;
  margin: 0 auto;
  transform: translateY(-23vh);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1), 0 6px 20px rgba(0, 0, 0, 0.1);
  border-radius: 16rpx;

  .hr {
    margin-top: 15rpx;
    margin-bottom: 15rpx;
    border: 2px solid #f3f3f3;
    border-radius: 2px;
  }
}

.bottom {

  height: 6vh;
  width: 70vw;
  margin: 0 auto;
  transform: translateY(-21vh);
  left: 15vw;
  border-radius: 60rpx;
  overflow: auto;
}
</style>